package by.airlanterns.service;

import by.airlanterns.dao.ActionDaoImpl;
import by.airlanterns.dto.SiteAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Sergey
 * Date: 29.01.13
 * Time: 16:16
 * To change this template use File | Settings | File Templates.
 */
@Service
public class ActionService {

    @Autowired
    private ActionDaoImpl actionDao;

    public void save(SiteAction action) {
        actionDao.save(action);
    }

    public void savOrUpdate(SiteAction action) {
        actionDao.saveOrUpdate(action);
    }

    public SiteAction findById(int id) {
        return actionDao.findById(id);
    }


    public SiteAction getAction() {
        List<SiteAction> actionList = actionDao.findAll();
        if (actionList != null && actionList.size() != 0) {
            return actionList.get(0);
        }

        return null;

//        actionDao.findById(1);
    }

    public SiteAction getActiveAction() {
        List<SiteAction> actionList = actionDao.findAll();
        if (actionList != null && actionList.size() != 0) {
            if (actionList.get(0).getActivated().equals(by.airlanterns.dto.enums.Enum.yes))
                return actionList.get(0);
            else
                return new SiteAction();
        }

        return new SiteAction();

    }


}
